/*
* author :chensuiyi
* time	 :2017/10/11
* version:1.0.0
*/
;(function(){
	var str = document.querySelectorAll('script[type="CHJS"]');
	//静态标记
	var staticToken = {
		'值':'value',
		'类名':'className',
		'内文本':'innerText',
		'函数结束':'}',
		'如果结束':'}',
		'文档':'document'
	}
	//关键字标记
	var token = {
		'函数定义':function(x){
			return 'function ' + x[1] + '(' + x.splice(2,x.length).join(',') + '){';
		},
		'如果':function(x){
			x = x.map(function(v,i,a){
				return staticToken[v] || v;
			})
			return 'if(' + x.splice(1,x.length).join('') + '){';
		},
		'否则':function(x){
			return '}else{';
		},
		'唯一元素':function(x){
			return 'getElementById(' + x.splice(1,x.length).join('') + '){';
		},
		'默认':function(x){
			x = x.map(function(v,i,a){
				return staticToken[v] || v;
			})
			return x.join('')+';';
		}
	}
	//语法转化
	str.forEach(function(v,i){
		//初级转化
		var syntax = [];
		//中级转化
		var code = [];
		//最终源码
		var source = '';
		v.innerText.replace(/^\n+/gi,'').replace(/\s+$/gi,'').split(/\n+/gi).forEach(function(v,i){
			var line = [];
			var key = v.replace(/^\s+/gi,'').replace(/\s+$/gi,'').replace(/(\.)/gi,' $1 ').split(/\s+/gi);
			line.push(token[key[0]] ? token[key[0]](key) : token['默认'](key));
			syntax.push(line);
		});
		syntax.forEach(function(v,i){
			code.push(v.join());
		})
		source = code.join('');
		var script = document.createElement('script');
		script.innerText = source;
		document.body.appendChild(script)
	})
})();
			